package com.nurese.service;

import com.github.pagehelper.PageHelper;
import com.nurese.dao.CareworkerDao;
import com.nurese.entity.Careworker;
import com.nurese.utils.BeanMapUtils;
import com.nurese.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CareworkerService {
    @Autowired
    private CareworkerDao careworkerDao;
    public int create(Careworker careworker){
        return careworkerDao.create(careworker);
    }
    public int delete(Integer id){
//        Map<String,Object> map=new HashMap<>();
//        map.put("id",id);
//        return careworkerDao.delete(map);

        return careworkerDao.delete(MapParameter.getInstance().addId(id).getMap());
    }
    public int delete(String ids){

        String[] arr=ids.split(",");
        int flag=0;
        for (String s:arr){
            flag=careworkerDao.delete(MapParameter.getInstance().addId(Integer.parseInt(s)).getMap());
        }
        return flag;
    }
    public int update(Careworker careworker){
//        Map<String,Object> map= BeanMapUtils.beanToMapForUpdate(Careworker);
//        return careworkerDao.update(map);

        return careworkerDao.update(MapParameter.getInstance()
                .add(BeanMapUtils.beanToMapForUpdate(careworker))
                .addId(careworker.getId()).getMap());

    }
    public List<Careworker> query(Careworker careworker){
        if (careworker !=null && careworker.getPage() !=null){
            PageHelper.startPage(careworker.getPage(),careworker.getLimit());
        }
        return careworkerDao.query(BeanMapUtils.beanToMap(careworker));
    }
    public int count(Careworker careworker){
        return careworkerDao.count(BeanMapUtils.beanToMap(careworker));
    }
    public Careworker detail(Integer id){
        return careworkerDao.detail(MapParameter.getInstance().add("id",id).getMap());
    }
}
